// 引入路由
import Router from 'vue-router'
import Vue from 'vue'

Vue.use(Router)

const Login = () => import('../views/Login.vue')
const Main = () => import('../views/Main.vue')

const Dict = () => import('../views/sys/dict/index.vue')
const User = () => import('../views/sys/user/index.vue')

const routes = [{
		path: '/',
		name: 'login',
		component: Login,
		meta: {
			title: "登录"
		}
	},
	{
		path: '/main',
		name: 'main',
		component: Main,
		meta: {
			title: "主页面"
		},
		// 嵌套路有
		children: [{
				path: '/dict',
				name: 'dict',
				component: Dict,
				meta: {
					title: "字典"
				}
			},
			{
				path: '/user',
				name: 'user',
				component: User,
				meta: {
					title: "用户管理"
				}
			},
		]
	},

]

//创建路由
var router = new Router({
	routes
})

// 配置全局前置守卫前置
router.beforeEach((to, from, next) => {
	// 根据组件的meta动态更换标题
	document.title = to.meta.title
	next()
})

export default router;
